// ============================== 导入依赖 ============================== //

import API from './API'

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  async remoteInfo({ state: { infoParam } }) {
    const obj = await API.getInfo(infoParam)
    return transInfo(obj)
  },
}

// ============================== 转换方法 ============================== //

const transInfo = (obj) => {
  const totalList = obj.head || []
  const typeList = obj.info || []
  const total = totalList.find((item) => item.name === 'total') || {}
  const online = typeList.find((item) => item.name === 'online') || {}
  const offline = typeList.find((item) => item.name === 'off') || {}
  const error = typeList.find((item) => item.name === 'error') || {}

  return {
    total: total.value || 0,
    online: online.value || 0,
    offline: offline.value || 0,
    error: error.value || 0,
  }
}
